//
//  AppDelegate.swift
//  swiftWEIbo
//
//  Created by mac－gt on 15/11/23.
//  Copyright © 2015年 mac－gt. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UINavigationBar.appearance().tintColor=UIColor.orangeColor()
        window=UIWindow(frame: UIScreen.mainScreen().bounds)
//        let tabBarVC=GTMainViewController()
        window?.rootViewController=tranformController()
        window?.makeKeyAndVisible()
        return true
    }
     //  根据是否登录 显示欢迎界面/新特性界面
    func tranformController()->UIViewController{
        if !GTAcounts.isLogin(){
            return GTMainViewController()
        }
        return isNewFeature() ? GTNewFeatureController() : GTWelcomeController()
        
    }
    // 是否是新版本
    func isNewFeature()->Bool{
         let currentVersionString=NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String
        let currentVersion=Double(currentVersionString)
        let befoureVersionKey="befoureVersionKey"
        let befoureVersion=NSUserDefaults.standardUserDefaults().doubleForKey(befoureVersionKey)
        NSUserDefaults.standardUserDefaults().setDouble(currentVersion!, forKey: befoureVersionKey)
        return currentVersion != befoureVersion
    }
    //  根据操作执行界面跳转
    func switchRootController(isMain: Bool) {
        window?.rootViewController = isMain ? GTMainViewController() : GTWelcomeController()
    }
}

